package com.acwing.partition11;

import java.io.*;
import java.util.LinkedList;

/**
 * @author `RKC`
 * @date 2021/12/26 10:11
 */
public class AC1098城堡问题 {

    private static final int N = 55, M = 55;
    private static final int[][] graph = new int[N][M], dirs = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
    private static boolean[][] visited = new boolean[N][M];

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split("\\s+");
        int n = Integer.parseInt(s[0]), m = Integer.parseInt(s[1]);
        for (int i = 0; i < n; i++) {
            s = reader.readLine().split("\\s+");
            for (int j = 0; j < m; j++) graph[i][j] = Integer.parseInt(s[j]);
        }
        resolve(n, m);
        writer.flush();
    }

    private static void resolve(int n, int m) throws IOException {
        int answer1 = 0, answer2 = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (visited[i][j]) continue;
                answer2 = Math.max(answer2, bfs(i, j, n, m));
                answer1++;
            }
        }
        writer.write(answer1 + "\n");
        writer.write(answer2 + "\n");
    }

    private static int bfs(int x, int y, int n, int m) {
        int area = 0;
        LinkedList<int[]> queue = new LinkedList<>();
        queue.addLast(new int[]{x, y});
        visited[x][y] = true;
        while (!queue.isEmpty()) {
            int[] curr = queue.pollFirst();
            area++;
            for (int i = 0; i < dirs.length; i++) {
                int a = dirs[i][0] + curr[0], b = dirs[i][1] + curr[1];
                if (a < 0 || a >= n || b < 0 || b >= m) continue;
                if (visited[a][b] || (graph[curr[0]][curr[1]] >> i & 1) == 1) continue;
                queue.addLast(new int[]{a, b});
                visited[a][b] = true;
            }
        }
        return area;
    }
}
